package com.atguigu.daijia.driver.controller;

import com.atguigu.daijia.common.login.GuiguLogin;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.driver.service.OcrService;
import com.atguigu.daijia.model.vo.driver.DriverLicenseOcrVo;
import com.atguigu.daijia.model.vo.driver.IdCardOcrVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@Tag(name = "腾讯云识别接口管理")
@RestController
@RequestMapping(value="/ocr")
@SuppressWarnings({"unchecked", "rawtypes"})
public class OcrController {

    @Autowired
    private OcrService ocrService;

    /**
     * 腾讯云识别身份证认证接口
     * @param file
     * @return
     */
    @Operation(summary = "身份证识别")
    @GuiguLogin
    @PostMapping("/idCardOcr")
    public Result<IdCardOcrVo> uploadDriverLicenseOcr(@RequestPart("file") MultipartFile file) {
        //TODO 使用真实的身份证测试
        //return Result.ok(ocrService.idCardOcr(file));


        //使用直接的数据
        IdCardOcrVo idCardOcrVo = new IdCardOcrVo();
        idCardOcrVo.setName("乐");
        idCardOcrVo.setGender("2");
        try {
            idCardOcrVo.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse("1999-11-01"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        idCardOcrVo.setIdcardNo("445221199911017222");
        idCardOcrVo.setIdcardAddress("广东省揭阳市揭东县");
        try {
            idCardOcrVo.setIdcardExpire(new SimpleDateFormat("yyyy-MM-dd").parse("1999-11-01"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        idCardOcrVo.setIdcardFrontUrl("/driver/idCard/a63229655a2cc03274695a64615ec73.png");
        idCardOcrVo.setIdcardFrontShowUrl("https://leforlearn-1323965456.cos.ap-nanjing.myqcloud.com/a63229655a2cc03274695a64615ec73.png");
        idCardOcrVo.setIdcardBackUrl("/driver/idCard/a63229655a2cc03274695a64615ec73.png");
        idCardOcrVo.setIdcardBackShowUrl("https://leforlearn-1323965456.cos.ap-nanjing.myqcloud.com/a63229655a2cc03274695a64615ec73.png");
        return Result.ok(idCardOcrVo);
    }

    /**
     * 腾讯云识别驾驶证认证接口
     * @param file
     * @return
     */
    @Operation(summary = "驾驶证识别")
    @GuiguLogin
    @PostMapping("/driverLicenseOcr")
    public Result<DriverLicenseOcrVo> driverLicenseOcr(@RequestPart("file") MultipartFile file) {
        //TODO 使用真实的驾驶证测试
        //return Result.ok(ocrService.driverLicenseOcr(file));

        //直接使用编制数据
        DriverLicenseOcrVo driverLicenseOcrVo = new DriverLicenseOcrVo();
        driverLicenseOcrVo.setName("乐");
        driverLicenseOcrVo.setDriverLicenseClazz("C1");
        driverLicenseOcrVo.setDriverLicenseNo("411481199101017222");
        try {
            driverLicenseOcrVo.setDriverLicenseExpire(new SimpleDateFormat("yyyy-MM-dd")
                    .parse("2015-11-01"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        try {
            driverLicenseOcrVo.setDriverLicenseIssueDate(new SimpleDateFormat("yyyy-MM-dd")
                    .parse("2019-11-01"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        driverLicenseOcrVo.setDriverLicenseFrontUrl("https://leforlearn-1323965456.cos.ap-nanjing.myqcloud.com/a63229655a2cc03274695a64615ec73.png");
        driverLicenseOcrVo.setDriverLicenseFrontShowUrl("https://leforlearn-1323965456.cos.ap-nanjing.myqcloud.com/a63229655a2cc03274695a64615ec73.png");
        driverLicenseOcrVo.setDriverLicenseBackUrl("https://leforlearn-1323965456.cos.ap-nanjing.myqcloud.com/a63229655a2cc03274695a64615ec73.png");
        driverLicenseOcrVo.setDriverLicenseBackShowUrl("https://leforlearn-1323965456.cos.ap-nanjing.myqcloud.com/a63229655a2cc03274695a64615ec73.png");
        return Result.ok(driverLicenseOcrVo);
    }


}

